package classroom.edu.info.manager.service;

import classroom.edu.info.manager.dao.TeacherDao;
import classroom.edu.info.manager.domain.Teacher;

public class TeacherService {
    private TeacherDao teacherDao = new TeacherDao();


    public boolean addTeacher(Teacher tea) {

        return teacherDao.addTeacher(tea);
    }

    public boolean isExists(String id) {
        Teacher[] teacher = teacherDao.selectTeacher();
        boolean exists = false;
        for (int i = 0; i < teacher.length; i++) {
            Teacher tea = teacher[i];
            if (tea != null && id.equals(tea.getId())) {
                exists = true;
                break;
            }
        }
        return exists;
    }

    public Teacher[] selectTeacher() {
        Teacher[] teacher = teacherDao.selectTeacher();
        for (int i = 0; i < teacher.length; i++) {
            if (teacher[i] != null) {
                return teacher;
            }
        }
        return null;
    }


    public void deleteTeacher(String id) {
        teacherDao.deleteTeacher(id);
    }

    public boolean isNull() {
        Teacher[] teacher = teacherDao.selectTeacher();
        for (int i = 0; i < teacher.length; i++) {
            if (teacher[i]!=null){
                return true;
            }
        }
        return false;
    }


    public void updateTeacher(Teacher newTeacher) {
        teacherDao.updateTeacher(newTeacher);
    }
}

